﻿''****************************************************************
'' 这是护理电子病历表单报表后台运行支持脚本
'' 注意：这是Visual Basic脚本，您可以不区分大小写 
'' 请不要修改系统提供的方法名，以及方法名前面的Overrides关键字
'' Script Language : Visual Basic
'' Author : YangMingkun, Date : 2012-6-6
'' Copyright (C) Heren Health Services (SUPCON) Co.,Ltd.
''****************************************************************

'报表脚本初始化
Public Overrides Sub Initialize()

End Sub

'更新表单报表
'Public Overrides Function UpdateReport(ByVal param As String, ByVal data As Object) As Boolean
'  Me.NotifyPageCompleted()
'End Function
'更新病人信息
Private Sub UpdatePatientInfo()
    Dim value As New Object
    Me.GetSystemContext("病人姓名", value)
    Me.SetElementValue("XTextBox1", value)

    Me.GetSystemContext("病人性别", value)
    Me.SetElementValue("XTextBox2", value)

    Me.GetSystemContext("病人年龄", value)
    Me.SetElementValue("XTextBox3", value)

    Me.GetSystemContext("诊断", value)
    Me.SetElementValue("XTextBox4", value)

    Me.GetSystemContext("床号", value)
    Me.SetElementValue("XTextBox5", value)

    Me.GetSystemContext("住院号", value)
    Me.SetElementValue("XTextBox6", value)

    Me.GetSystemContext("病人ID号", value)
    Me.SetElementValue("XTextBox7", value)


End Sub

Private ContinuedPrintIndex As Integer = 0
Private SetStartPageNumber As Integer = 1
Private ContinuedPrint As Boolean = False

'更新表单报表
Public Overrides Function UpdateReport(ByVal param As String, ByVal data As Object) As Boolean
    If param = "续打行号" Then
        Me.ContinuedPrintIndex = CType(data, Integer)
    ElseIf param = "是否续打" Then
        Me.ContinuedPrint = CType(data, Boolean)
    ElseIf param = "设置打印起始页码" Then
        Me.SetStartPageNumber = CType(data, Integer)
    ElseIf param = "打印数据" Then
        Me.UpdatePatientInfo()
        Me.PrintData(data)
    End If
End Function


''填充实际的打印数据
Public Sub PrintData(ByVal data As DataTable)

    Dim PrintData As DataTable = Me.GetPrintData(data)

    '计算页数
    Dim pageCount As Integer = PrintData.Rows.Count \ 17
    If PrintData.Rows.Count Mod 17 <> 0 Then pageCount += 1

    '计算这个页数，对应的总行数
    Dim rowCount As Integer = pageCount * 17
    Dim TempIndex As Integer = 0

    '用于标记当前页是否是续打的
    Dim page_print_continued As Boolean = False

    Dim separator As Char() = {";"c}
    Dim FirstRowDateStr As String = ""
    Dim FirstRowTimeStr As String = ""

    For recordIndex As Integer = TempIndex To rowCount - 1

        Dim rowIndex As Integer = recordIndex Mod 17
        '清楚原先的记录
        Me.ClearCache(rowIndex)

        Dim printed As Boolean = Me.ToBoolValue(Me.GetFieldValue(PrintData, recordIndex, "printed"), True)
        If rowIndex = 0 Then
            If Me.ContinuedPrint AndAlso printed = False Then
                page_print_continued = True
                Me.SetElementVisible(False)
            Else
                page_print_continued = False
                Me.SetElementVisible(True)
            End If
        End If
        If Not printed AndAlso page_print_continued Then
            Continue For
        End If


        Dim dateTimeStr As String = Me.GetFieldValue(PrintData, recordIndex, "Column1").toString()
        If dateTimeStr.Trim().Length > 5 Then
            Dim arrDateStr As String() = dateTimeStr.Split(separator)
            Me.SetElementValue("日期_" + (rowIndex + 1).toString(), arrDateStr(0).Replace("-", "/"))
            Me.SetElementValue("时间_" + (rowIndex + 1).toString(), arrDateStr(1))
        Else
            Me.SetElementValue("日期_" + (rowIndex + 1).toString(), "")
            Me.SetElementValue("时间_" + (rowIndex + 1).toString(), dateTimeStr)
        End If

        Dim DateElement As TextFieldElement = CType(Me.FindOneElement("日期_" + (rowIndex + 1).toString()), TextFieldElement)
        Dim DateElementText As String = DateElement.Text.Trim()
        Dim TimeElement As TextFieldElement = CType(Me.FindOneElement("时间_" + (rowIndex + 1).toString()), TextFieldElement)
        Dim TimeElementText As String = TimeElement.Text.Trim()
        If DateElementText <> "" Then
            FirstRowDateStr = DateElementText
        End If
        If TimeElementText <> "" Then
            FirstRowTimeStr = TimeElementText
        End If
        If rowIndex = 0 Then
            If DateElementText = "" Then
                Me.SetElementValue("日期_" + (rowIndex + 1).toString(), FirstRowDateStr)
            End If
            If TimeElementText = "" Then
                Me.SetElementValue("时间_" + (rowIndex + 1).toString(), FirstRowTimeStr)
            End If
        End If

        Me.SetElementValue("心率_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "心率"))
        Me.SetElementValue("心律_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "心律"))
        Me.SetElementValue("意识_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "意识"))

        Me.SetElementValue("T_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "体温"))
        Me.SetElementValue("脉搏_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "脉搏"))
        Me.SetElementValue("R_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "呼吸"))
        If (Me.GetFieldValue(PrintData, recordIndex, "血压").Trim() <> "/") Then
            Me.SetElementValue("BP_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "血压"))
        End If
        '        Dim bool_value As String = Me.GetFieldValue(PrintData, recordIndex, "心电监护")
        '        
        '        Me.SetElementValue("心电监护_" + (rowIndex + 1).toString(), bool_value)
        Me.SetElementValue("SA02_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "血氧饱和度"))
        Me.SetElementValue("BS_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "血糖"))

        Dim ruliangName As String = Me.GetFieldValue(PrintData, recordIndex, "入量名称")
        Dim fuheyizhubiaoji As String = Me.GetFieldValue(PrintData, recordIndex, "复合医嘱标记")
        '  messagebox.show(ruliangName)
        Dim ruliangBeiYongValue As String = Me.GetFieldValue(PrintData, recordIndex, "备用量")
        ' messagebox.show(ruliangBeiYongValue)
        Dim ruliangValue As String = Me.GetFieldValue(PrintData, recordIndex, "实用量")
        Dim tujingValue As String = Me.GetFieldValue(PrintData, recordIndex, "途径")
        Dim chuliangName As String = Me.GetFieldValue(PrintData, recordIndex, "出量名称")
        Dim chuliangValue As String = Me.GetFieldValue(PrintData, recordIndex, "出量")

        '        Dim ruLiangLineElement1 As LineElement = CType(Me.FindOneElement("实用量红线1_" + (rowIndex + 1).toString()), LineElement)
        '        Dim ruLiangLineElement2 As LineElement = CType(Me.FindOneElement("实用量红线2_" + (rowIndex + 1).toString()), LineElement)
        '        Dim chuLiangLineElement1 As LineElement = CType(Me.FindOneElement("出量红线1_" + (rowIndex + 1).toString()), LineElement)
        '        Dim chuLiangLineElement2 As LineElement = CType(Me.FindOneElement("出量红线2_" + (rowIndex + 1).toString()), LineElement)         

        If (ruliangName.Contains("小结") OrElse ruliangName.Contains("总结")) AndAlso ruliangValue.Trim() <> "" Then
            Me.SetElementValue("入量名称_" + (rowIndex + 1).toString(), ruliangName)
            '  Me.SetElementValue("flag_" + (rowIndex + 1).toString(), fuheyizhubiaoji)
            Me.SetElementValue("备用量_" + (rowIndex + 1).toString(), ruliangBeiYongValue)
            Me.SetElementValue("使用量_" + (rowIndex + 1).toString(), ruliangValue)
            Me.SetElementValue("途径_" + (rowIndex + 1).toString(), tujingValue)
            '              ruLiangLineElement1.Visible = True
            '              ruLiangLineElement2.Visible = True
            If chuliangName.Trim() <> "" Then
                Me.SetElementValue("出量名称_" + (rowIndex + 1).toString(), chuliangName)
                '                    chuLiangLineElement1.Visible = True
                '                    chuLiangLineElement2.Visible = True
            End If

            If chuliangValue.Trim() <> "" Then
                Me.SetElementValue("量_" + (rowIndex + 1).toString(), chuliangValue)
                '                    chuLiangLineElement1.Visible = True
                '                    chuLiangLineElement2.Visible = True
            End If
        ElseIf (chuliangName.Contains("小结") OrElse chuliangName.Contains("总结")) AndAlso chuliangName.Trim() = "" _
                 AndAlso chuliangName.Trim() <> "" Then
            Me.SetElementValue("出量名称_" + (rowIndex + 1).toString(), chuliangName)
            Me.SetElementValue("量_" + (rowIndex + 1).toString(), chuliangValue)
            '              chuLiangLineElement1.Visible = True
            '              chuLiangLineElement2.Visible = True
        ElseIf (ruliangName.Contains("小结") OrElse ruliangName.Contains("总结")) AndAlso ruliangValue.Trim() = "" _
                AndAlso chuliangValue.Trim() = "" Then
        Else
            Me.SetElementValue("入量名称_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "入量名称"))
            Me.SetElementValue("flag_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "复合医嘱标记"))
            Me.SetElementValue("备用量_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "备用量"))
            Me.SetElementValue("使用量_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "实用量"))
            Me.SetElementValue("途径_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "途径"))
            Me.SetElementValue("出量名称_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "出量名称"))
            Me.SetElementValue("量_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "出量"))
        End If

        '        Me.SetElementValue("颜色性状_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "出量颜色"))
        '        Me.SetElementValue("管道名称_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "管道名称"))
        '        Me.SetElementValue("管道情况_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "管道情况"))
        Me.SetElementValue("手术敷料_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "手术敷料"))
        Me.SetElementValue("皮肤_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "皮肤"))

        '        bool_value = Me.GetFieldValue(PrintData, recordIndex, "吸痰")
        ''        showMessage(bool_value.toString())
        '        If bool_value = "吸痰" Then
        '            Me.SetElementValue("吸痰_" + (rowIndex + 1).toString(), "√")
        '        ElseIf bool_value = "" Then
        '            Me.SetElementValue("吸痰_" + (rowIndex + 1).toString(), "")
        '        Else
        '            Me.SetElementValue("吸痰_" + (rowIndex + 1).toString(), "")
        '        End If

        '        Me.SetElementValue("血C_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "血糖/CVP"))
        '        Me.SetElementValue("心率_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "心率"))
        Me.SetElementValue("简述_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "护理措施"))
        '        Me.SetElementValue("签名_" + (rowIndex + 1).toString(), Me.GetFieldValue(PrintData, recordIndex, "签名"))

        If recordIndex >= rowCount - 1 OrElse rowIndex = 16 Then
            Me.SetElementValue("页码", "第 " & (Me.SetStartPageNumber + CInt((recordIndex + 1) \ 17) - 1).ToString() & " 页")
            Me.NotifyPageCompleted()
        End If
    Next recordIndex
End Sub

Private Sub SetElementVisible(ByVal visible As Boolean)

    '设置界面上的数框为空
    Dim elements As ElementBase() = Me.FindElement("文本")
    If elements IsNot Nothing Then
        For i As Integer = 0 To elements.length - 1
            elements(i).Visible = visible
        Next
    End If

    elements = Me.FindElement("行列表格")
    If elements IsNot Nothing Then
        For i As Integer = 0 To elements.length - 1
            elements(i).Visible = visible
        Next
    End If

    Dim element As ElementBase = Me.FindOneElement("XTextBox1")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox2")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox3")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox4")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox5")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox6")
    element.Visible = visible

    element = Me.FindOneElement("XTextBox7")
    element.Visible = visible

    elements = Me.FindElement("直线段")
    If elements IsNot Nothing Then
        For i As Integer = 0 To elements.length - 1
            elements(i).Visible = visible
        Next
    End If

    element = Me.FindOneElement("页码")
    element.visible = visible

    '    element = Me.FindOneElement("矩形")
    '    element.visible = visible

    For index As Integer = 1 To 24
        Dim line As LineElement = Me.FindOneElement("直线段" & index)
        If line IsNot Nothing Then
            line.visible = visible
        End If
    Next
End Sub

Public Function ClearCache(ByVal rowIndex As Integer)
    Me.SetElementValue("日期_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("时间_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("心律_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("意识_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("T_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("心率_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("脉搏_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("R_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("BP_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("SA02_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("BS_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("入量名称_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("flag_" + (rowIndex + 1).toString(), "")

    Me.SetElementValue("备用量_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("使用量_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("途径_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("出量名称_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("量_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("手术敷料_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("皮肤_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("简述_" + (rowIndex + 1).toString(), "")
    Me.SetElementValue("页码", "")
End Function


''获取打印的所有行数据
Public Function GetPrintData(ByVal data As DataTable) As DataTable

    ''获取列宽度和字体,以便计算分行
    Dim Width_RuLiangName As Integer = 60
    Dim Font_RuLiangName As Font = New Font("宋体", 7.0F)
    Dim element As TextFieldElement = Me.FindElement("入量名称_1")(0)
    If element IsNot Nothing Then
        Width_RuLiangName = element.Width
        Font_RuLiangName = element.TextFont
    End If

    Dim Width_ChuLiangName As Integer = 60
    Dim Font_ChuLiangName As Font = New Font("宋体", 7.0F)
    element = Me.FindElement("出量名称_1")(0)
    If element IsNot Nothing Then
        Width_ChuLiangName = element.Width
        Font_ChuLiangName = element.TextFont
    End If

    Dim Width_ShiLiangName As Integer = 60
    Dim Font_ShiLiangName As Font = New Font("宋体", 7.0F)
    element = Me.FindElement("使用量_1")(0)
    If element IsNot Nothing Then
        Width_ShiLiangName = element.Width
        Font_ShiLiangName = element.TextFont
    End If

    Dim Width_TuJing As Integer = 60
    Dim Font_TuJing As Font = New Font("宋体", 7.0F)
    element = Me.FindElement("途径_1")(0)
    If element IsNot Nothing Then
        Width_TuJing = element.Width
        Font_TuJing = element.TextFont
    End If

    Dim Width_CuoShi As Integer = 150
    Dim Font_CuoShi As Font = New Font("宋体", 7.0F)
    element = Me.FindElement("简述_1")(0)
    If element IsNot Nothing Then
        Width_CuoShi = element.Width
        Font_CuoShi = element.TextFont
    End If

    Dim Width_PiFu As Integer = 150
    Dim Font_PiFu As Font = New Font("宋体", 7.0F)
    element = Me.FindElement("皮肤_1")(0)
    If element IsNot Nothing Then
        Width_PiFu = element.Width
        Font_PiFu = element.TextFont
    End If


    Dim PrintData As DataTable = Me.CloneTable(data)
    ''打印标识字段
    PrintData.Columns.Add("printed")
    ''处理同一天的记录只显示日期一次,跨年份显示年份
    Dim arrDateStr(data.Rows.Count) As String

    For rowIndex As Integer = 0 To data.Rows.Count - 1
        Dim RecordTime1 As DateTime
        DateTime.TryParse(Me.GetFieldValue(data, rowIndex, "Column1"), RecordTime1)
        For nextRowIndex As Integer = rowIndex + 1 To data.Rows.Count - 1
            Dim RecordTime2 As DateTime
            DateTime.TryParse(Me.GetFieldValue(data, nextRowIndex, "Column1"), RecordTime2)
            If RecordTime1.Date = RecordTime2.Date Then
                arrDateStr(nextRowIndex) = RecordTime2.ToString("H:mm")
                rowIndex = rowIndex + 1
            ElseIf RecordTime1.Date <> RecordTime2.Date AndAlso RecordTime1.Year <> RecordTime2.Year Then
                arrDateStr(nextRowIndex) = RecordTime2.ToString("yyyy-MM-dd HH:mm:ss")
                Exit For
            Else
                Exit For
            End If
        Next nextRowIndex
    Next rowIndex

    For rowIndex As Integer = 0 To data.Rows.Count - 1
        If arrDateStr(rowIndex) Is Nothing Then
            data.Rows(rowIndex)("Column1") = data.Rows(rowIndex)("Column1").SubString(5, 5) + ";" + data.Rows(rowIndex)("Column1").SubString(11, 5)
        ElseIf arrDateStr(rowIndex).Length <= 5 Then
            data.Rows(rowIndex)("Column1") = arrDateStr(rowIndex)
        Else
            data.Rows(rowIndex)("Column1") = arrDateStr(rowIndex).SubString(0, 10) + ";" + arrDateStr(rowIndex).SubString(11, 5)
        End If
    Next rowIndex



    ''分行处理
    For rowIndex As Integer = 0 To data.Rows.Count - 1

        ''对一些特殊列分行
        Dim CellValue As String = Me.GetFieldValue(data, rowIndex, "护理措施")
        Dim arrCuoShi As String() = Me.GetTextLines(CellValue, Font_CuoShi, Width_CuoShi)

        CellValue = Me.GetFieldValue(data, rowIndex, "出量名称")
        '        Dim arrChuLiangName As String() = Me.GetTextLines(CellValue, Font_ChuLiangName, Width_ChuLiangName)
        Dim arrChuLiangName As String() = GetTextLinesByEnter(CellValue)

        CellValue = Me.GetFieldValue(data, rowIndex, "出量")
        Dim arrChuLiangValue As String() = Me.GetTextLines(CellValue, Font_ChuLiangName, 1000)

        '        CellValue = Me.GetFieldValue(data, rowIndex, "出量颜色")
        ''        Dim arrChuLiangColor As String() = Me.GetTextLines(CellValue, Font_ChuLiangName, 1000)
        '         Dim arrChuLiangColor As String() = GetTextLinesByEnter(CellValue)

        CellValue = Me.GetFieldValue(data, rowIndex, "入量名称")
        '        Dim arrRuLiangName As String() = Me.GetTextLines(CellValue, Font_RuLiangName, Width_RuLiangName)
        Dim arrRuLiangName As String() = GetTextLinesByEnter(CellValue)


        CellValue = Me.GetFieldValue(data, rowIndex, "复合医嘱标记")
        '        Dim arrRuLiangName As String() = Me.GetTextLines(CellValue, Font_RuLiangName, Width_RuLiangName)
        Dim arrFuHeYiZhuBiaoJi As String() = GetTextLinesByEnter2(CellValue)

        CellValue = Me.GetFieldValue(data, rowIndex, "备用量")
        ' messagebox.show(CellValue)
        Dim arrRuLiangValue As String() = Me.GetTextLines(CellValue, Font_RuLiangName, 1000)
        '        messagebox.show(arrRuLiangValue.tostring())
        '         
        CellValue = Me.GetFieldValue(data, rowIndex, "实用量")
        Dim arrShiYongLiangValue As String() = Me.GetTextLines(CellValue, Font_ShiLiangName, 1000)

        CellValue = Me.GetFieldValue(data, rowIndex, "途径")
        '        Dim arrGuanDaoName As String() = Me.GetTextLines(CellValue, Font_GuanDaoName, Width_GuanDaoName)
        Dim arrTuJingName As String() = Me.GetTextLinesByEnter2(CellValue)
        '
        '        CellValue = Me.GetFieldValue(data, rowIndex, "管道情况")
        ''        Dim arrGuanDaoValue As String() = Me.GetTextLines(CellValue, Font_GuanDaoName, 1000)
        '        Dim arrGuanDaoValue As String() = GetTextLinesByEnter(CellValue)

        CellValue = Me.GetFieldValue(data, rowIndex, "皮肤")
        '        Dim arrPiFuValue As String() = Me.GetTextLines(CellValue, Font_PiFu, Width_PiFu)
        Dim arrPiFuValue As String() = GetTextLinesByEnter(CellValue)

        '计算出最大行数
        Dim Max_Line_Count As Integer = 1
        If Max_Line_Count < arrCuoShi.Length Then Max_Line_Count = arrCuoshi.Length
        If Max_Line_Count < arrChuLiangName.Length Then Max_Line_Count = arrChuLiangName.Length
        If Max_Line_Count < arrChuLiangValue.Length Then Max_Line_Count = arrChuLiangValue.Length
        '        If Max_Line_Count < arrChuLiangColor.Length Then Max_Line_Count = arrChuLiangColor.Length
        If Max_Line_Count < arrRuLiangName.Length Then Max_Line_Count = arrRuLiangName.Length
        If Max_Line_Count < arrFuHeYiZhuBiaoJi.Length Then Max_Line_Count = arrFuHeYiZhuBiaoJi.Length

        If Max_Line_Count < arrRuLiangValue.Length Then Max_Line_Count = arrRuLiangValue.Length
        If Max_Line_Count < arrShiYongLiangValue.Length Then Max_Line_Count = arrShiYongLiangValue.Length
        If Max_Line_Count < arrTuJingName.Length Then Max_Line_Count = arrTuJingName.Length
        '        If Max_Line_Count < arrGuanDaoValue.Length Then Max_Line_Count = arrGuanDaoValue.Length
        If Max_Line_Count < arrPiFuValue.Length Then Max_Line_Count = arrPiFuValue.Length

        ''创建新的DataTable
        For index As Integer = 0 To Max_Line_Count - 1

            ''创建行的值的数组
            Dim values(data.Columns.Count - 1) As String

            ''给值的数组赋值
            For columnIndex As Integer = 0 To data.Columns.Count - 1

                values(columnIndex) = String.Empty
                If index = 0 Then
                    values(columnIndex) = Me.GetFieldValue(data, rowIndex, columnIndex)
                End If

                If data.Columns(columnIndex).ColumnName = "入量名称" Then
                    values(columnIndex) = Me.GetArrayItem(arrRuLiangName, index)
                ElseIf data.Columns(columnIndex).ColumnName = "复合医嘱标记" Then
                    values(columnIndex) = Me.GetArrayItem(arrFuHeYiZhuBiaoJi, index)

                ElseIf data.Columns(columnIndex).ColumnName = "备用量" Then
                    values(columnIndex) = Me.GetArrayItem(arrRuLiangValue, index)
                ElseIf data.Columns(columnIndex).ColumnName = "实用量" Then
                    values(columnIndex) = Me.GetArrayItem(arrShiYongLiangValue, index)
                ElseIf data.Columns(columnIndex).ColumnName = "出量名称" Then
                    values(columnIndex) = Me.GetArrayItem(arrChuLiangName, index)
                ElseIf data.Columns(columnIndex).ColumnName = "出量" Then
                    values(columnIndex) = Me.GetArrayItem(arrChuLiangValue, index)
                ElseIf data.Columns(columnIndex).ColumnName = "途径" Then
                    values(columnIndex) = Me.GetArrayItem(arrTuJingName, index)
                    '                ElseIf data.Columns(columnIndex).ColumnName = "出量颜色" Then
                    '                    values(columnIndex) = Me.GetArrayItem(arrChuLiangColor, index)
                    '                ElseIf data.Columns(columnIndex).ColumnName = "管道名称" Then
                    '                    values(columnIndex) = Me.GetArrayItem(arrGuanDaoName, index)
                    '                ElseIf data.Columns(columnIndex).ColumnName = "管道情况" Then
                    '                    values(columnIndex) = Me.GetArrayItem(arrGuanDaoValue, index)
                ElseIf data.Columns(columnIndex).ColumnName = "皮肤" Then
                    values(columnIndex) = Me.GetArrayItem(arrPiFuValue, index)
                ElseIf data.Columns(columnIndex).ColumnName = "护理措施" Then
                    values(columnIndex) = Me.GetArrayItem(arrCuoShi, index)

                End If
            Next columnIndex
            ''根据值的数组创建行
            '            If index = Max_Line_Count - 1 Then
            '               values(data.Columns.Count - 2) = Me.GetFieldValue(data, rowIndex, "签名")
            '            Else If index = 0 Then
            '               values(index) = Me.GetFieldValue(data, rowIndex, "Column1")
            ''               ShowMessage(values(index).toString())
            '            End If
            PrintData.Rows.Add(values)

            If rowIndex < Me.ContinuedPrintIndex Then
                PrintData.Rows(PrintData.Rows.Count - 1)("printed") = False
            Else
                PrintData.Rows(PrintData.Rows.Count - 1)("printed") = True
            End If

        Next index
    Next rowIndex
    Return PrintData
End Function

'按换行符对指定的字符串文本进行分行
Private Function GetTextLinesByEnter(ByVal text As String) As String()
    If text Is Nothing Then
        Return New String() {""}
    End If
    Dim lines As New List(Of String)
    lines.AddRange(text.Split(vbCrLf))

    '去除分出来的多余空白行
    Dim index As Integer = lines.Count - 1
    While index >= 0
        If lines(index).Trim() = "" Then lines.RemoveAt(index)
        index = index - 1
    End While

    Return lines.toarray()
End Function
'按换行符对指定的字符串文本进行分行,不去除空白行
Private Function GetTextLinesByEnter2(ByVal text As String) As String()
    If text Is Nothing Then
        Return New String() {""}
    End If
    Dim lines As New List(Of String)
    lines.AddRange(text.Split(vbCrLf))

    '    '去除分出来的多余空白行
    '    Dim index As Integer = lines.Count - 1
    '    While index >= 0
    '        If lines(index).Trim() = "" Then lines.RemoveAt(index)
    '        index = index - 1
    '    End While

    Return lines.toarray()
End Function